package com.zz.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.data.Rows;
import lombok.experimental.UtilityClass;

import java.util.Date;
import java.util.List;

@UtilityClass
public class WordUtil {


    public RowRenderData getSaleRowData(String name, JSONObject detail) {
        Integer m1 = detail.getInteger("m1");
        Integer m2 = detail.getInteger("m2");
        Integer m3 = detail.getInteger("m3");
        Integer m4 = detail.getInteger("m4");
        Integer m5 = detail.getInteger("m5");
        Integer m6 = detail.getInteger("m6");
        Integer m7 = detail.getInteger("m7");
        Integer m8 = detail.getInteger("m8");
        Integer m9 = detail.getInteger("m9");
        Integer m10 = detail.getInteger("m10");
        Integer m11 = detail.getInteger("m11");
        Integer m12 = detail.getInteger("m12");
        int sum = m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 + m9 + m10 + m11 + m12;
        return Rows.of(name,
                detail.getString("year"),
                String.valueOf(m1), String.valueOf(m2), String.valueOf(m3), String.valueOf(m4),
                String.valueOf(m5), String.valueOf(m6), String.valueOf(m7), String.valueOf(m8),
                String.valueOf(m9), String.valueOf(m10), String.valueOf(m11), String.valueOf(m12),
                String.valueOf(sum)
        ).textFontFamily("微软雅黑")
                .textFontSize(12)
                .center().create();
    }

    public RowRenderData getSumRowData(List<JSONObject> saleList) {

        int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0, sum7 = 0, sum8 = 0, sum9 = 0, sum10 = 0, sum11 = 0, sum12 = 0;
        for (JSONObject sale : saleList) {
            List<JSONObject> detailList = sale.getJSONArray("detail").toJavaList(JSONObject.class);
            for (JSONObject detail : detailList) {
                sum1 += detail.getInteger("m1");
                sum2 += detail.getInteger("m2");
                sum3 += detail.getInteger("m3");
                sum4 += detail.getInteger("m4");
                sum5 += detail.getInteger("m5");
                sum6 += detail.getInteger("m6");
                sum7 += detail.getInteger("m7");
                sum8 += detail.getInteger("m8");
                sum9 += detail.getInteger("m9");
                sum10 += detail.getInteger("m10");
                sum11 += detail.getInteger("m11");
                sum12 += detail.getInteger("m12");
            }
        }
        int total = sum1 + sum2 + sum3 + sum4 + sum5 + sum6 + sum7 + sum8 + sum9 + sum10 + sum11 + sum12;
        return Rows.of("合计",
                "0", // 用于占位
                String.valueOf(sum1), String.valueOf(sum2), String.valueOf(sum3), String.valueOf(sum4),
                String.valueOf(sum5), String.valueOf(sum6), String.valueOf(sum7), String.valueOf(sum8),
                String.valueOf(sum9), String.valueOf(sum10), String.valueOf(sum11), String.valueOf(sum12),
                String.valueOf(total)

        ).textFontFamily("微软雅黑")
                .textFontSize(12)
                .center().create();
    }


    public JSONObject getSaleData() {
        JSONObject data = new JSONObject();

        data.put("id", "199864000016667302");
        data.put("operationId", "199864000016667302");
        data.put("province", "河北");
        data.put("product", "盐酸纳美芬注射液");
        data.put("size", "1ml:0.1mg");
        data.put("enterprise", "成都天台山制药有限公司");
        data.put("year", DateUtil.getYearByDate(new Date()));
        data.put("month", DateUtil.getMonthByDate(new Date()));
        data.put("day", DateUtil.getDayByDate(new Date()));

        JSONArray list = new JSONArray();

        JSONObject hos2 = new JSONObject();
        hos2.put("name", "元氏县医院");
        JSONArray detail2 = new JSONArray();
        JSONObject hosData2 = new JSONObject();
        hosData2.put("year", "2022年");
        hosData2.put("m1", 0);
        hosData2.put("m2", 0);
        hosData2.put("m3", 3020);
        hosData2.put("m4", 4020);
        hosData2.put("m5", 5020);
        hosData2.put("m6", 3020);
        hosData2.put("m7", 3020);
        hosData2.put("m8", 3020);
        hosData2.put("m9", 3020);
        hosData2.put("m10", 3000);
        hosData2.put("m11", 3000);
        hosData2.put("m12", 3000);
        JSONObject hosData22 = new JSONObject();
        hosData22.put("year", "2023年");
        hosData22.put("m1", 0);
        hosData22.put("m2", 0);
        hosData22.put("m3", 3030);
        hosData22.put("m4", 4030);
        hosData22.put("m5", 5030);
        hosData22.put("m6", 3030);
        hosData22.put("m7", 3030);
        hosData22.put("m8", 3030);
        hosData22.put("m9", 3030);
        hosData22.put("m10", 3000);
        hosData22.put("m11", 3000);
        hosData22.put("m12", 3000);
        JSONObject hosData222 = new JSONObject();
        hosData222.put("year", "2024年");
        hosData222.put("m1", 0);
        hosData222.put("m2", 0);
        hosData222.put("m3", 3030);
        hosData222.put("m4", 4030);
        hosData222.put("m5", 5030);
        hosData222.put("m6", 3030);
        hosData222.put("m7", 3030);
        hosData222.put("m8", 3030);
        hosData222.put("m9", 3030);
        hosData222.put("m10", 3000);
        hosData222.put("m11", 3000);
        hosData222.put("m12", 3000);
        JSONObject hosData2222 = new JSONObject();
        hosData2222.put("year", "2025年");
        hosData2222.put("m1", 0);
        hosData2222.put("m2", 0);
        hosData2222.put("m3", 3030);
        hosData2222.put("m4", 4030);
        hosData2222.put("m5", 5030);
        hosData2222.put("m6", 3030);
        hosData2222.put("m7", 3030);
        hosData2222.put("m8", 3030);
        hosData2222.put("m9", 3030);
        hosData2222.put("m10", 3000);
        hosData2222.put("m11", 3000);
        hosData2222.put("m12", 3000);
        JSONObject hosData22222 = new JSONObject();
        hosData22222.put("year", "2026年");
        hosData22222.put("m1", 0);
        hosData22222.put("m2", 0);
        hosData22222.put("m3", 3030);
        hosData22222.put("m4", 4030);
        hosData22222.put("m5", 5030);
        hosData22222.put("m6", 3030);
        hosData22222.put("m7", 3030);
        hosData22222.put("m8", 3030);
        hosData22222.put("m9", 3030);
        hosData22222.put("m10", 3000);
        hosData22222.put("m11", 3000);
        hosData22222.put("m12", 3000);
        detail2.add(hosData22222);
        detail2.add(hosData2222);
        detail2.add(hosData222);
        detail2.add(hosData22);
        detail2.add(hosData2);
        hos2.put("detail", detail2);
        list.add(hos2);



        JSONObject hos1 = new JSONObject();
        hos1.put("name", "唐山市人民医院(唐山市肿瘤医院)");
        JSONArray detail1 = new JSONArray();
        JSONObject hosData = new JSONObject();
        hosData.put("year", "2022年");
        hosData.put("m1", 0);
        hosData.put("m2", 0);
        hosData.put("m3", 3002);
        hosData.put("m4", 4002);
        hosData.put("m5", 5002);
        hosData.put("m6", 3002);
        hosData.put("m7", 3002);
        hosData.put("m8", 3002);
        hosData.put("m9", 3002);
        hosData.put("m10", 3000);
        hosData.put("m11", 3000);
        hosData.put("m12", 3000);
        JSONObject hosData11 = new JSONObject();
        hosData11.put("year", "2023年");
        hosData11.put("m1", 0);
        hosData11.put("m2", 0);
        hosData11.put("m3", 3003);
        hosData11.put("m4", 4003);
        hosData11.put("m5", 5003);
        hosData11.put("m6", 3003);
        hosData11.put("m7", 3003);
        hosData11.put("m8", 3003);
        hosData11.put("m9", 3003);
        hosData11.put("m10", 3000);
        hosData11.put("m11", 3000);
        hosData11.put("m12", 3000);
        JSONObject hosData111 = new JSONObject();
        hosData111.put("year", "2024年");
        hosData111.put("m1", 0);
        hosData111.put("m2", 0);
        hosData111.put("m3", 3004);
        hosData111.put("m4", 4004);
        hosData111.put("m5", 5004);
        hosData111.put("m6", 3004);
        hosData111.put("m7", 3004);
        hosData111.put("m8", 3004);
        hosData111.put("m9", 3004);
        hosData111.put("m10", 3000);
        hosData111.put("m11", 3000);
        hosData111.put("m12", 3000);
        JSONObject hosData1111 = new JSONObject();
        hosData1111.put("year", "2025年");
        hosData1111.put("m1", 0);
        hosData1111.put("m2", 0);
        hosData1111.put("m3", 3005);
        hosData1111.put("m4", 4005);
        hosData1111.put("m5", 5005);
        hosData1111.put("m6", 3005);
        hosData1111.put("m7", 3005);
        hosData1111.put("m8", 3005);
        hosData1111.put("m9", 3005);
        hosData1111.put("m10", 3000);
        hosData1111.put("m11", 3000);
        hosData1111.put("m12", 3000);

        detail1.add(hosData1111);
        detail1.add(hosData111);
        detail1.add(hosData11);
        detail1.add(hosData);
        hos1.put("detail", detail1);
        list.add(hos1);



        data.put("list", list);
        return data;
    }

    public JSONObject getSaleChangeData() {
        JSONObject data = new JSONObject();

        data.put("id", "199864000016668200");
        data.put("operationId", "199864000016667302");
        data.put("province", "上海");
        data.put("hosName", "松江区中心医院");
        data.put("product", "盐酸氯化钠纳美芬注射液");
        data.put("size", "1ml:0.1mg");
        data.put("enterprise", "成都天台山制药有限公司");
        data.put("year", DateUtil.getYearByDate(new Date()));
        data.put("month", DateUtil.getMonthByDate(new Date()));
        data.put("day", DateUtil.getDayByDate(new Date()));

        data.put("name", "松江区中心医院-乐萌0.1mg");
        JSONArray list = new JSONArray();
        for (int i = 0; i < 9; i++) {
            JSONObject j1 = new JSONObject();
            j1.put("year", "20190" + i);
            j1.put("before", 100 + i);
            j1.put("after", 200 + i);
            list.add(j1);
        }


        data.put("list", list);
        return data;
    }

}
